package logic

import (
	"context"
	"shop_srv/shopclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrdersLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrdersLogic {
	return &CreateOrdersLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateOrdersLogic) CreateOrders(req *types.CreateOrdersRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	orders, err := l.svcCtx.ShopSrv.CreateOrders(l.ctx, &shopclient.CreateOrdersRequest{
		UserId:  req.UserID,
		GoodsId: req.GoodsId,
		Num:     req.Num,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "订单创建成功",
		Code:    200,
		Data:    orders,
	}, nil
}
